package com.ssg.poultry;

import java.util.List;

import org.apache.log4j.Logger;

import com.ssg.poultry.service.SerialPortService;

import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;

public class App {
	
	public static void main(String[] args) throws Exception {
		Logger logger = Logger.getLogger(App.class);
		logger.debug(System.getProperty("java.home"));
		logger.debug("start list Serial Ports:");
		SerialPortService sps = new SerialPortService(115200, 1);
		List<CommPortIdentifier> all = sps.listPort();
		for(CommPortIdentifier cp:all) {
			logger.debug(cp.getName());
		}
		SerialPort port = sps.connPort("COM4");
		sps.writeHex(port, "AB0401800100");
		
		byte[] read = sps.readFromPort(port, 12);
		
		sps.writeHex(port, "AB 04 01 80 03 00");
		
		Thread.sleep(500);
		
		read = sps.readFromPort(port);
		
		Thread.sleep(500);
		
		read = sps.readFromPort(port);
	}
}
